
cc.Class({
    extends: cc.Component,

    properties: {
        // 重力
        offset: 0,
        GPencent: 0 
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        cc.log(this.offset);
        this.G = 0.98 / this.GPencent;
        this.t = 0;
        this.anim = this.getComponent(cc.Animation);
        this.anim.play('bird0');
        this.registerInput();
    },

    start() {

    },
    onCollisionEnter(other, self) {
        let group = cc.game.groupList[other.node.groupIndex];
        cc.log(group);
        if (group === 'score') {
            D.game.addScore();
        } else if (group === 'land' || group === 'pencil') {
            cc.log('gameOVer');
            this.anim.stop('bird0');
            D.game.gameOver();
        }
    },

    update(dt) {
        if (!D.game.run) {
            return;
        }
        this.node.y -= (this.G * this.t * (this.t - this.offset)) / 2;
        this.t++;
    },

    registerInput() {
        D.game.node.on('touchstart', event => {
            this.t = 0;
        })
    }

});
